<?php


//---------------------------------O2O相关路由--------------------------------
$router->group(['prefix' => 'O2O'], function () use ($router) {

    $router->get('test', 'UserController@test');

    $router->post('login', 'AuthController@issueToken');

    $router->post('clerk/update/pwd', 'AuthController@updatePassword');
    //登陆协议
    $router->get('clerk/getLoginAgreemen', 'AuthController@getLoginAgreemen');

    $router->get('store/list', 'GoodsController@index')->name('api.o2o.store.list');
    $router->get('store/getGoodsList', 'GoodsController@getGoodsList')->name('api.o2o.store.getGoodsList');
    $router->get('store/{id}/edit', 'GoodsController@edit')->name('api.o2o.store.edit');

    $router->get('getScanData', 'BarCodeController@getScanData');

    $router->group(['middleware' => ['auth:clerk', 'O2O']], function ($router) {
//    首页
        $router->group(['prefix' => 'home'], function () use ($router) {

            $router->get('index', 'HomeController@index');

            $router->get('get/qr/{code}', 'HomeController@getClerkQRCode');
        });

//    导购管理
        $router->group(['prefix' => 'clerk'], function () use ($router) {

            $router->get('list', 'ClerkController@index');

            $router->get('edit/{id}', 'ClerkController@edit');

            $router->post('update/{id}', 'ClerkController@update');

            $router->post('upload/avatar', 'ClerkController@uploadAvatar');

            $router->post('updateNickname', 'ClerkController@updateNickname');

            $router->get('me', 'ClerkController@me');

            $router->get('bonus', 'ClerkController@bonus');

            $router->get('count', 'ClerkController@count');
        });

//    会员管理
        $router->group(['prefix' => 'user'], function () use ($router) {

            $router->get('list', 'UserController@index');

            $router->get('info/{user_id}', 'UserController@info');

            $router->get('coupon/{user_id}', 'UserController@getCoupon');

            $router->get('point/{user_id}', 'UserController@getPoint');

            $router->get('point/list/{user_id}', 'UserController@pointList');

            $router->post('search', 'UserController@search');

        });

        //下单流程
        $router->group(['prefix' => 'store'], function () use ($router) {

            $router->get('code/{code}', 'BarCodeController@index');

            $router->get('getMiniQrCode', 'BarCodeController@getMiniQrCode');
        });


        $router->group(['prefix' => 'shopping'], function () use ($router) {

            $router->post('order/checkout', 'ShoppingController@checkout');

            $router->post('order/confirm', 'ShoppingController@confirm');

            $router->post('order/charge', 'PaymentController@createCharge');

            $router->post('order/wx_pub_qr', 'PaymentController@getWxPayQRCode');

            $router->post('order/check/pay', 'PaymentController@checkOrderPay');

            $router->post('order/amount/pay', 'PaymentController@amountConfirmArrival');

            $router->post('order/cancel', 'ShoppingController@cancel');

            $router->post('order/delete', 'ShoppingController@delete');

            $router->get('order/extraInfo/{user_id}', 'ShoppingController@extraInfo');

            //购物车
            $router->post('cart', 'ShoppingCartController@store')->name('api.o2o.shopping.cart.store');
            $router->get('cart', 'ShoppingCartController@index')->name('api.o2o.shopping.cart');
            $router->put('cart/{id}', 'ShoppingCartController@update')->name('api.o2o.shopping.cart.put');
            $router->delete('cart/{id}', 'ShoppingCartController@delete')->name('api.o2o.shopping.cart.delete');
            $router->post('cart/clear', 'ShoppingCartController@clear')->name('api.o2o.shopping.cart.clear');
            $router->get('cart/count', 'ShoppingCartController@count')->name('api.o2o.shopping.cart.count');


        });


        $router->group(['prefix' => 'order'], function () use ($router) {

            $router->get('list', 'OrderController@getOrders');

            $router->get('detail/{order_no}', 'OrderController@getOrderDetails');

            $router->post('/upload/ticket', 'OrderController@uploadTicket');

        });


        $router->group(['prefix' => 'upload'], function () use ($router) {

            $router->post('/', 'UploadController@index');

        });


        //余额相关
        $router->group(['prefix' => 'balance'], function () use ($router) {

            $router->get('clerk_owner/mobile', 'BalanceController@getClerkOwnerMobile');

            $router->get('sum/{user_id}', 'BalanceController@sum');

            $router->post('charge/{user_id}', 'BalanceController@charge');

            $router->post('paid', 'BalanceController@paid');

            $router->get('detail/{order_no}', 'BalanceController@detail');

            $router->post('/upload/ticket', 'BalanceController@uploadTicket');

            $router->post('amount/pay', 'BalanceController@amountConfirmArrival');


            $router->get('user/{user_id}', 'BalanceController@UserBalance');

            $router->get('record', 'BalanceController@BalanceRecord');

            $router->get('opBalanceBase', 'BalanceController@opBalanceBase');
            $router->post('handleBalance', 'BalanceController@handleBalance');
        });

        $router->group(['prefix' => 'point'], function () use ($router) {

            $router->get('opPointBase', 'PointController@opPointBase');
            $router->post('handlePoint', 'PointController@handlePoint');

        });


        $router->group(['prefix' => 'coupon'], function () use ($router) {
            $router->get('getCouponDetail', 'CouponController@getCouponDetail');
            $router->post('closureCoupon', 'CouponController@closureCoupon');
        });

        //售后
        $router->group(['prefix' => 'refund'], function () use ($router) {
            $router->get('base_info', 'RefundController@baseInfo')->name('api.o2o.refund.base_info');
            $router->post('applyReturn', 'RefundController@applyReturn')->name('api.o2o.refund.apply_return');
            $router->post('refundProcessor', 'RefundController@refundProcessor')->name('api.o2o.refund.refundProcessor');
            $router->post('applyExchange', 'RefundController@applyExchange')->name('api.o2o.refund.applyExchange');
            $router->get('show/{refund_no}', 'RefundController@show')->name('api.o2o.refund.show');
        });
    });

    //打印

    $router->group(['prefix' => 'print'], function ($router) {
        $router->get('/', 'PrintController@index')->name('api.print.index');

        $router->get('img2Base64', 'PrintController@img2Base64')->name('api.print.img2Base64');

        $router->post('qrcodeData', 'PrintController@qrcodeData')->name('api.print.qrcodeData');
        $router->get('getQrcodeData', 'PrintController@getQrcodeData')->name('api.print.getQrcodeData');

        $router->get('draw2PxPoint', 'PrintController@draw2PxPoint')->name('api.print.draw2PxPoint');
    });

    //用户门店购物相关,暂未添加middleware
    $router->group(['prefix' => 'user/shopping', 'namespace' => 'O2oUser'], function () use ($router) {
        $router->get('getStock/{id}', 'GoodsController@getStock')->name('api.o2o.user.goods.getStock');
        $router->get('getLocalShop', 'ShopLocalController@getLocalShop');
        
        $router->group(['middleware' => ['auth:shop']], function () use ($router) {
            $router->post('cart', 'ShoppingCartController@store')->name('api.o2o.user.shopping.cart.store');
            $router->get('cart', 'ShoppingCartController@index')->name('api.o2o.user.shopping.cart');
            $router->put('cart/{id}', 'ShoppingCartController@update')->name('api.o2o.user.shopping.cart.put');
            $router->delete('cart/{id}', 'ShoppingCartController@delete')->name('api.o2o.user.shopping.cart.delete');
            $router->post('cart/clear', 'ShoppingCartController@clear')->name('api.o2o.user.shopping.cart.clear');
            $router->get('cart/count', 'ShoppingCartController@count')->name('api.o2o.user.shopping.cart.count');

            $router->post('order/checkout', 'ShoppingController@checkout')->name('api.o2o.user.shopping.order.checkout');
            $router->post('order/checkout/point', 'ShoppingController@checkoutPoint')->name('api.o2o.user.shopping.order.checkout.point');
            $router->post('order/confirm', 'ShoppingController@confirm')->name('api.o2o.user.shopping.order.confirm');
            $router->post('order/confirm/point', 'ShoppingController@confirmPoint')->name('api.o2o.user.shopping.order.confirm');
            //$router->post('order/charge', 'PaymentController@createCharge')->name('api.o2o.user.shopping.order.charge');
            //$router->post('order/paid', 'PaymentController@paidSuccess')->name('api.o2o.user.shopping.order.paid');
            $router->get('shopping/order/extraInfo', 'ShoppingController@extraInfo')->name('api.o2o.user.shopping.order.extraInfo');

            $router->post('shopping/order/calculate', 'ShoppingController@calculateDiscount')->name('api.o2o.user.shopping.order.calculate');
        });
        $router->post('shoppingCart/discount', 'DiscountController@shoppingCartDiscount')->name('api.o2o.shopping.cart.discount');

    });


});